package com.zhuiyun.project.api.articlereport.controller;


import com.zhuiyun.project.api.articlereport.model.ReportModel;
import com.zhuiyun.project.api.articlereport.service.ReportService;

import com.zhuiyun.project.api.dict.entity.DictData;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ArticleController
 * @Description TODO
 * @Author 韩佳轩
 * @Date 2023/6/15 10:35
 **/
@RequestMapping("/Sys")
// @RestController = @controller + @responseBody
@RestController
//支持跨越请求
@CrossOrigin
public class ReportController {
    @Autowired
    private ReportService reportService;

    @GetMapping("/ReportArticle")
    public CommonResult getReportAll(ReportModel reportModel, PageRequest pageRequest){
        return CommonResult.ok(reportService.reportAll(reportModel,pageRequest));
    }

    @DeleteMapping("/updateAgree")
    public CommonResult getUpdateAgree(int id,String processorName,String rejectionReason){
        int i = reportService.updateAgree(id,processorName,rejectionReason);
        if (i > 0) {
            return CommonResult.ok("已同意");
        } else {
            return CommonResult.error("失败");
        }
    }

    @PutMapping("/updateReject")
    public CommonResult getupdateReject(ReportModel reportModel){
        int i = reportService.updateReject(reportModel);
        if (i > 0) {
            return CommonResult.ok("驳回成功");
        } else {
            return CommonResult.error("驳回失败");
        }
    }

    @PostMapping("/addReport")
    public CommonResult getAddReport(@RequestBody ReportModel reportModel){
        int i = reportService.addReport(reportModel);
        if (i > 0) {
            return CommonResult.ok("举报成功");
        } else {
            return CommonResult.error("举报失败");
        }
    }

    @GetMapping("/ReportType")
    public CommonResult getReportType(DictData dictData){
        return CommonResult.ok(reportService.getReportType(dictData));
    }
}
